package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsSearchHistoryMapper;
import com.qf.pojo.DtsSearchHistory;
import com.qf.service.DtsSearchHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * projectName:workspace_6
 * author:hyn
 * time:2021/12/1 11:55
 * description:
 */
@Service
public class DtsSearchHistoryServiceImpl implements DtsSearchHistoryService {
    @Autowired
    private DtsSearchHistoryMapper searchHistoryMapper;

    @Override
    public IPage<DtsSearchHistory> findAll(String keyword, String userId, Integer limit, Integer page, String sort, String order) {
        IPage<DtsSearchHistory> ipage = new Page(page,limit);
        QueryWrapper<DtsSearchHistory> wrapper = new QueryWrapper<>();
        wrapper.select("id,user_id,keyword,`from`,add_time,update_time,deleted");
        if(!StringUtils.isEmpty(keyword)){
            wrapper.like("keyword",keyword);
        }
        if(!StringUtils.isEmpty(userId)){
            wrapper.like("user_id",userId);
        }
        if("asc".equals(order)){
            wrapper.orderByAsc(sort);
        }else{
            wrapper.orderByDesc(sort);
        }
        IPage<DtsSearchHistory> p = searchHistoryMapper.selectPage(ipage, wrapper);
        return p;
    }
}
